﻿using System;
using System.Diagnostics;
using System.Reflection;
using StoryQ;

namespace BankInvest.InstrumentEditor.Tests.AcceptanceTests
{
    internal static class StoryExtensions
    {
        internal static string FriendlyName(this MethodBase @this)
        {
            return @this.Name.Between("<", ">").Replace("_", " ");
        }

        internal static string Between(this string @this, string from, string to)
        {
            var right = @this.Substring(@this.IndexOf(@from) + 1);
            
            return right.Substring(0, right.IndexOf(to));
        }

        internal static Scenario WithNamedScenario(this Feature @this)
        {
            return @this.WithScenario(new StackFrame(1).GetMethod().FriendlyName());
        }

        internal static void WithScenario(this Feature @this, Func<Feature, Outcome> scenario)
        {
            scenario(@this).ExecuteWithReport();
        }
    }
}